<?php

declare(strict_types=1);

namespace App\Controller\Ws;

use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\WebSocketServer\Sender;

/**
 * @AutoController
 */
class ServerController
{
    /**
     * @Inject()
     * @var Sender
     */
    protected $sender;

    public function close(int $fd)
    {
        go(function () use ($fd) {
            $this->sender->disconnect($fd);
        });

        return '';
    }

    public function send($fd,$data)
    {
        $rel = $this->sender->push(intval($fd), json_encode($data));

        return $rel;
    }
}
